﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>上级培训计划</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="../../static/css/font.css" rel="stylesheet" />
    <link href="../../static/css/weadmin.css" rel="stylesheet" />
    <link href="../../lib/layui/css/layui.css" rel="stylesheet" />
    <script src="../../../lib/layui/layui.js"></script>

</head>
<body>
    <div class="layui-fluid fluid-position">
        <div class="layui-row">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-collapse" lay-accordion lay-filter="infos_form">
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">上级培训计划筛选</h2>
                            <div class="layui-colla-content">
                                <div class="layui-form layui-form-pane">

                                    <!--计划名称-->
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">计划名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" placeholder="计划名称" class="layui-input" maxlength="50" id="TPName" />
                                        </div>
                                    </div>



                                    <!--时间-->
                                    <div class="layui-form-item">
                                        <!--<label class="layui-form-label">计划编号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="计划编号" class="layui-input" maxlength="8" />
                                        </div>-->
                                        <div class="layui-inline">
                                            <label class="layui-form-label">发布时间</label>
                                            <div class="layui-input-inline">
                                                <input type="text" class="layui-input" id="TPReleaseStart" />
                                            </div>
                                            <label class="layui-form-label layui-form-label-inner layui-form-label-inner-w1">至</label>
                                            <div class="layui-input-inline layui-form-label-inner">
                                                <input type="text" class="layui-input" id="TPReleaseEnd" />
                                            </div>
                                        </div>
                                        <!--<div class="layui-inline">
                                            <label class="layui-form-label">发布</label>
                                            <div class="layui-input-block">
                                                <select id="TPIsRelease" class="layui-tree-more">
                                                    <option value=""></option>
                                                    <option value="0">未发布</option>
                                                    <option value="1">已发布</option>
                                                </select>
                                            </div>
                                        </div>-->

                                    </div>


                                    <!--<div class="layui-form-item">
                                        <div class="layui-form-label">选择部门</div>
                                        <div class="layui-input-block">
                                            <input type="text" autocomplete="off" readonly="" id="selectDatas" placeholder="请选择" class="layui-input" />
                                            <div class="eleTree" lay-filter="data5"></div>
                                        </div>
                                    </div>-->

                                    <!--计划描述-->
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">计划内容</label>
                                        <div class="layui-input-block">
                                            <textarea name="" placeholder="计划内容" class="layui-textarea" maxlength="500" id="TPDescribe"></textarea>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>

                </div>
                <div class="layui-card-header layui-btn-container">
                    <button type="button" class="layui-btn layui-btn-primary" id="find"><i class="layui-icon">&#xe615;</i>查询</button>
                    <button type="button" class="layui-btn layui-btn-primary" id="reset"><i class="layui-icon">&#xe669;</i>清空</button>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-fluid" id="infos">
        <table id="dataList" lay-filter="dataList"></table>
    </div>
    <script>
        var selectCurrentCPID = 0;//集团id
        var selectCurrentID = 0;// 当前选中的 id  [用于修改]
        var selectCurrentName = "";//选择当前信息的name 
        var selectContent = "";
        var selectContent1 = "";
        var selectAnnexUrl = "";
        var selectAnnexName = "";
        var currentDeptLevelId = 0;//当前部门级别  0：是段
        var currentInfoDeptId = 0;//当前选中信息的 部门id
        var currentPreDepId = 0;//当前上级部门id
        var selectdata = function () {
            var data = {
                RefID: selectCurrentID,
                RefName: selectCurrentName,
                Content: selectContent,
                Content1: selectContent1,
                AnnexUrl: selectAnnexUrl,
                AnnexName: selectAnnexName,
                CPID: selectCurrentCPID
            }
            return data;
        };
        //加载 [赋值]获取数据  (部门相关数据)
        var dataSelect = [];
        var temp_deptId_List = [];//列表中选择信息时   使用字段中的内容=>为其赋值,可以使用此字段保存

        var dataCurent = [];
        var th = 0;
        var tw = 0;
        
        layui.use(['form', 'laydate', 'table', 'jquery', 'element', 'layer', 'tree', 'util'], function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            th = $(document).height();
            tw = $(document).width();
            var table = layui.table;
            var form = layui.form;
            var element = layui.element;
            var layer = layui.layer;
            var eleTree = layui.tree;
            
            form.on('switch(switch)', function (data) { });
            laydate.render({ elem: '#TPReleaseStart', trigger: 'click' });
            laydate.render({ elem: '#TPReleaseEnd', trigger: 'click' });
            function PageInit() {
                var obj = $("div[lay-id='dataList']");
                var child = $(".layui-table-body");
                var off = obj.offset().top;
                var c = th - off - 100;
                child.attr("style", "height:" + c + "px");
            }
            element.on('collapse(infos_form)', function (data) {
                PageInit();
            });
            var selfType = GetQueryString("plan");
            $.ajax({
                url: ApiUrl + "Dep/SelTree",
                type: 'post',
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
                success: function (data) {
                    if (data.StatusCode == 200) {
                        dataSelect = data.Data;
                        //$("#DepID").append("<option value=''></option>");
                        //$(data.Data).each(function (index, item) {
                        //    $("#DepID").append("<option value='" + item.DepID + "'>" + item.DepName + "</option>");
                        //});
                        //form.render();//必须，不然动态加载项不显示
                    }
                    else if (data.StatusCode == 403) {
                        //layer.alert(data.Info, function () {
                        //    location.href = './login.html';
                        //})
                    }
                    else {
                        //layer.msg(data.Info);
                    }
                }
            });
            var tempList = [];
            function SetTextFromTree(v)
            {
                for (var i = 0; i < v.length;i++)
                {
                    var c = v[i];
                    tempList.push({ id: c.id, title: c.title });
                    temp_deptId_List.push(c.id);
                    var a = $("#selectDatas").val();
                    if (a!=""){a += ",";}
                    $("#selectDatas").val(a+c.title);
                    if (c.children != undefined) {
                        if (c.children.length > 0) {
                            SetTextFromTree(c.children);
                        }
                    }
                }
            }
            function setTree()//选择信息列表中 信息时 调用该方法  并为temp_deptId_List赋值
            {
                eleTree.setChecked('eleTreeid', temp_deptId_List);
            }
            var el_tree;
            $("#selectDatas").on("click", function (e) {
                e.stopPropagation();
                loadTree();
                $(".eleTree").toggle();
            });
            function loadTree() {
                el_tree =
                    eleTree.render({
                        elem: '.eleTree',
                        id: 'eleTreeid',
                        data: dataSelect,
                        defaultExpandAll: false,
                        expandOnClickNode: false,
                        highlightCurrent: true
                        , checkStrictly: true
                        , showCheckbox: true
                        , oncheck: function (obj) {
                            $("#selectDatas").val("");
                            temp_deptId_List = [];
                            tempList = [];
                            SetTextFromTree(el_tree.getChecked());
                        }
                    });
            }
          
            function showList() {
                var swhere = JSON.stringify({
                    TPName: $("#TPName").val(),
                    TPReleaseStart: $("#TPReleaseStart").val(),
                    TPReleaseEnd: $("#TPReleaseEnd").val(),
                    TPDescribe: $("#TPDescribe").val(),
                    //TPIsRelease: $("#TPIsRelease").val(),
                    self: selfType
                });
                table.render({
                    elem: '#dataList'
                    , url: ApiUrl + 'TrainPlan/Search'
                    , headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    }
                    , page: true
                    , cols: [[
                        { field: 'TPID', title: '编号', sort: true, hide: true },
                      
                        { field: 'TPName', title: '名称', width: 300 },
                        //{ field: 'TPDescribe', title: '每周两题', width: 300 },
                        //{ field: 'TPDescribeContent', title: '计划内容' },
                        {
                            field: 'TPReleaseStart', title: '开始时间', width: 120, templet: function (d) {
                                return d.TPReleaseStart.substring(0, 10);
                            },
                        },
                        {
                            field: 'TPReleaseEnd', title: '结束时间', width: 120, templet: function (d) {
                                return d.TPReleaseEnd.substring(0, 10);
                            },
                        },
                        //{ field: 'TPDesignUserID', title: '设计人员id', hide: true },
                        //{ field: 'TPDesignUserName', title: '设计人员姓名' },
                        //{ field: 'TPAddUserID', title: '添加人员id', hide: true },
                        //{ field: 'TPAddUserName', title: '添加人员姓名' },
                        //{
                        //    field: 'TPAddDateTime', title: '添加人员时间', width: 120, templet: function (d) {
                        //        return d.TPAddDateTime.substring(0, 10);
                        //    },
                        //},
                        { field: 'TPDepID', title: '计划部门', hide: true },
                        { field: 'CPID', title: '集团计划ID', hide: true },
                        { field: 'DepLevel', title: '制订计划部门层级', hide: true },
                        { field: 'TPDesignUserName', title: '制订人', width: 150 },
                        { field: 'AnnexUrl', title: '文件路径', sort: true, hide: true  },
                        { field: 'AnnexName', title: '文件名称', sort: true, hide: true  },
                        //{
                        //    field: 'TPIsRelease', title: '发布', width: 100, templet: function (d) {
                        //        return d.TPIsRelease == "0" ? "未发布" : "已发布";
                        //    }
                        //},
                        //{ field: 'IsUse', title: '是否在用', width: 100, templet: function (d) { return d.IsUse == "0" ? "未用" : "在用" } }
                    ]]
                    , where: { swhere: swhere }
                    , parseData: function (res) { //res 即为原始返回的数据
                        return {
                            "code": res.StatusCode, //解析接口状态
                            "msg": res.Info, //解析提示文本
                            "count": res.Count, //解析数据长度
                            "data": res.Data //解析数据列表
                        };
                    },
                    response: { statusCode: 200 },//规定成功的状态码，默认：0
                    event: true,
                    page: true,
                    done: function (res, curr, count) {
                       
                        //如果是异步请求数据方式，res即为你接口返回的信息。
                        //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度 
                        if (res.code == 403) {
                            layer.alert(res.msg, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                    }
                });
            }
            $(function () {
                showList();
                $("#sreach").click(function () {
                    showList();
                })
            })
            PageInit();
            function clearForm() {
                $("textarea").val("");
                $("input").val("");
            }
              //获取当前 部门级别id,部门id,上级部门id
            $.ajax({
                url: ApiUrl + "Dep/DeptLevel",//SelTree
                type: 'post',
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
                success: function (data) {
                    if (data.StatusCode == 200) {
                        currentDeptLevelId = data.Data.currentDeptLevelId;
                        cuurentDeptId = data.Data.cuurentDeptId;
                        currentPreDepId = data.Data.currentPreDepId;
                        GetDept(currentPreDepId);
                    }
                    else if (data.StatusCode == 403) {
                        layer.alert(data.Info, function () {
                            location.href = './login.html';
                        })
                    }
                    else {
                        layer.msg(data.Info);
                    }
                }
            });
            //获取下级部门列表树
            function GetDept(deptid) {
                var r = 0;
                $.ajax({
                    url: ApiUrl + "Dep/SelNextTree",//SelTree
                    type: 'post',
                    async: false,
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: { DepID: deptid },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            dataSelect = data.Data;
                            loadTree();
                            r = 1;
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                location.href = './login.html';
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
                return r;
            }
            //展示一条信息
            function GetSingleInfo(data) {
                $("#TPName").val(data.TPName);
                $("#TPDescribe").val(data.TPDescribe);
                $("#TPReleaseStart").val(data.TPReleaseStart.split('T')[0]);
                $("#TPReleaseEnd").val(data.TPReleaseEnd.split('T')[0]);
                temp_deptId_List = [];
                currentInfoDeptId = data.TPDepID;
                var r = GetDept(currentInfoDeptId);
                if (r == 1) {
                    if (data.TPSendDepID != null) {
                        if (data.TPSendDepID.indexOf(',') > -1) {
                            var tpids = data.TPSendDepID.split(',');
                            for (var i = 0; i < tpids.length; i++) {
                                temp_deptId_List.push(Number(tpids[i]));
                            }
                        }
                        else {
                            temp_deptId_List.push(Number(data.TPSendDepID));
                        }
                        setTree();
                    }
                }
               
            }

            ///按钮操作 开始
            //监听行单击事件（单击事件为：rowDouble）
            table.on('row(dataList)', function (obj) {
                var objtr = $(obj.tr.selector);
                $(".layui-table-body tr").attr("style","");
                objtr.attr("style","background:#00CC66;");
                    selectCurrentID = obj.data.TPID;
                selectCurrentName = obj.data.TPName;
                selectContent = obj.data.TPDescribe;
                selectContent1 = obj.data.TPDescribeContent;
                selectAnnexUrl = obj.data.AnnexUrl;
                selectAnnexName = obj.data.AnnexName;
                selectCurrentCPID = obj.data.CPID;
                    GetSingleInfo(obj.data);
            });


            $("#find").click(function () {
                showList();
            });


            $("#reset").click(function () {
                clearForm();
                temp_deptId_List = [];
                GetDept(currentPreDepId);
                setTree();
            });
            $("#add").click(function () {
                layer.open({
                    type: 2,
                    title: "集团计划上传",
                    area: ['900px', '600px'],
                    fixed: false, //不固定
                    maxmin: true,
                    content: './corpplan_upload.html',
                    end: function () {
                        location.reload();
                    }
                });
            });



            //编辑
            $("#edit").click(function () {
                alert("edit");
                //编辑保存 selectCurrentID
            });

            //删除
            $("#del").click(function () {
                layer.confirm('确定要删除吗?', function (index) {
                    alert("已删除");
                    //删除 selectIDs
                    layer.close(index);
                });
            });

            //审核
            $("#check").click(function () {
                //审核 selectIDs
                alert("审核");
            });


            //取消审核
            $("#uncheck").click(function () {
                layer.confirm('确定要取消审核吗?', function (index) {
                    //取消审核 selectIDs
                    alert("已取消审核");
                    layer.close(index);
                });
            });
            //发布
            $("#release").click(function () {
                alert("release");
                //发布 selectIDs
            });

            //取消发布
            $("#unrelease").click(function () {
                layer.confirm('确定要取消发布吗?', function (index) {
                    alert("已取消发布");
                    layer.close(index);
                    //取消发布 selectIDs
                });
            });





            //end
        });
    </script>
</body>
</html>